package models

import (
	"time"

	"gorm.io/gorm"
)

// MaRobotSalesInfo [...]
type MaRobotSalesInfo struct {
	RobotName             string    `gorm:"column:robot_name;type:varchar(50);comment:机器人名称" json:"robot_name" json_old:"RobotName"`
	SalesID               string    `gorm:"primaryKey;index:SalesID;column:sales_id;type:varchar(50);not null;comment:售货识别ID" json:"sales_id" json_old:"SalesID"`
	ContainerFloor        int       `gorm:"index:ContainerOne,priority:1,type:btree;column:container_floor;type:int(2) unsigned zerofill;not null;default:00;comment:货柜楼层" json:"container_floor" json_old:"ContainerFloor"`
	ContainerNum          int       `gorm:"primaryKey;index:ContainerOne,priority:2,type:btree;column:container_num;type:int(2) unsigned zerofill;not null;default:00;comment:货柜编号" json:"container_num" json_old:"ContainerNum"`
	AddTime               time.Time `gorm:"column:add_time;type:datetime;default:null;comment:创建时间" json:"-" json_old:"-"`
	AddTimeFormated       string    `gorm:"-" json:"add_time" json_old:"AddTime"`
	ClassID               string    `gorm:"index:ma_robot_sales_info_ibfk_4;column:class_id;type:bigint;default:null;comment:类目ID" json:"class_id" json_old:"ClassID"`
	GoodsID               string    `gorm:"index:ma_robot_sales_info_ibfk_5;column:goods_id;type:bigint;default:null;comment:商品ID" json:"goods_id" json_old:"GoodsID"`
	GoodsStatus           int       `gorm:"column:goods_status;type:int unsigned;not null;default:2;comment:商品状态（0-上架 1-缺货 2-下架）" json:"goods_status" json_old:"GoodsStatus"`
	GoodsInventory        int       `gorm:"column:goods_inventory;type:bigint unsigned;not null;default:0;comment:商品存货" json:"goods_inventory" json_old:"GoodsInventory"`
	GoodsReserveInventory int       `gorm:"column:goods_reserve_inventory;type:bigint unsigned;not null;default:0;comment:商品预留存货" json:"goods_reserve_inventory" json_old:"GoodsReserveInventory"`
	GoodsMaxInventory     int       `gorm:"column:goods_max_inventory;type:bigint unsigned;not null;default:0;comment:商品最高存货" json:"goods_max_inventory" json_old:"GoodsMaxInventory"`
	ContainerStatus       int       `gorm:"index:ContainerStatus;column:container_status;type:int unsigned;not null;default:1;comment:货柜状态【0-下架 1-上架】" json:"container_status" json_old:"ContainerStatus"`
	Sort                  int       `gorm:"column:sort;type:int;default:null" json:"sort" json_old:"Sort"`
	ContainerType         int       `gorm:"column:container_type;type:tinyint(1);not null;default:1;comment:单双货道 0无 1单 2双" json:"container_type" json_old:"ContainerType"`
	ContainerUseStatus    int       `gorm:"column:container_use_status;type:tinyint(1);not null;default:1;comment:1正常 2禁用" json:"container_use_status" json_old:"ContainerUseStatus"`
	CreatedAt             int64     `gorm:"index:created_at;column:created_at;autoCreateTime;type:int;size:64;comment:创建时间" json:"created_at"`
}

func (m *MaRobotSalesInfo) AfterFind(tx *gorm.DB) (err error) {
	if !m.AddTime.IsZero() {
		AddTimeByte, _ := DateTime(m.AddTime).MarshalDateTime()
		m.AddTimeFormated = string(AddTimeByte)
	}
	return
}

// TableName get sql table name.获取数据库表名
// func (m *MaRobotSalesInfo) TableName() string {
func (m MaRobotSalesInfo) TableName() string {
	return "ma_robot_sales_info"
}

// 模式自动注册
func init() {
	Models = append(Models, &MaRobotSalesInfo{})
}
